package com.xd.common.page;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Map;

public class Pagination {
    private static final String PARAMS_PAGE = "page";
    private static final String PARAMS_LIMIT = "limit";

    private Pagination() {
    }

    public static Page page(Map<String, Object> map) {
        long page = 0L;
        long limit = 0L;
        if (map.containsKey("page") && map.containsKey("limit")) {
            page = Long.parseLong(map.get("page").toString());
            limit = Long.parseLong(map.get("limit").toString());
        }

        return new Page(page, limit);
    }

    public static <T extends PaginationQuery> Page page(T page) {
        return new Page((long) page.getPage(), (long) page.getLimit());
    }

    public static Page page(Integer page, Integer limit) {
        return new Page((long) page, (long) limit);
    }
}
